package com.egao.common.manage.school;

import com.egao.common.core.annotation.ApiPageParam;
import com.egao.common.core.annotation.OperLog;
import com.egao.common.core.web.BaseController;
import com.egao.common.core.web.JsonResult;
import com.egao.common.core.web.PageParam;
import com.egao.common.core.web.PageResult;
import com.egao.common.module.cooperative.entity.CooperativeProjectBanner;
import com.egao.common.module.cooperative.service.CooperativeProjectBannerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 产教融合 校级内容管理
 * @author root
 */
@Api(tags = "产教融合 校级内容管理")
@RestController
@RequestMapping("${api}")
public class SchoolCooperativeCmsController extends BaseController {

    @Autowired
    private CooperativeProjectBannerService bannerService;

    private final static String title = "校级产教融合";

    @PreAuthorize("hasAuthority('school:cooperative-cms:list')")
    @ApiOperation(value = "产教融合校级banner列表")
    @ApiPageParam
    @GetMapping("/school/cooperative-cms/page")
    public PageResult<CooperativeProjectBanner> page(HttpServletRequest request) {
        PageParam<CooperativeProjectBanner> pageParam = new PageParam<>(request);
        return new PageResult<>(bannerService.listPage(pageParam), pageParam.getTotal());
    }

    @PreAuthorize("hasAuthority('school:cooperative-cms:insert')")
    @OperLog(value = title, desc = "添加修改banner", result = true)
    @ApiOperation(value = "添加banner")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "CooperativeProjectBanner", value = "CooperativeProjectBanner", required = true, dataType = "CooperativeProjectBanner")
    })
    @PostMapping("/school/cooperative-cms/insert")
    public JsonResult save(@RequestBody CooperativeProjectBanner cooperativeProjectBanner) {
        return bannerService.saveCooperativeProjectBanner(cooperativeProjectBanner);
    }

    @PreAuthorize("hasAuthority('school:cooperative-cms:update')")
    @OperLog(value = title, desc = "修改公开状态", result = true)
    @ApiOperation(value = "修改banner")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "CooperativeProjectBanner", value = "CooperativeProjectBanner", required = true, dataType = "CooperativeProjectBanner")
    })
    @PutMapping("/school/cooperative-cms/update")
    public JsonResult update(@RequestBody CooperativeProjectBanner cooperativeProjectBanner) {
        return bannerService.updateCooperativeProjectBanner(cooperativeProjectBanner);
    }

    @PreAuthorize("hasAuthority('school:cooperative-cms:delete')")
    @OperLog(value = title, desc = "删除banner", result = true)
    @ApiOperation(value = "删除banner")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "CooperativeProjectBanner", value = "CooperativeProjectBanner", required = true, dataType = "CooperativeProjectBanner")
    })
    @PutMapping("/school/cooperative-cms/delete")
    public JsonResult delete(@RequestBody CooperativeProjectBanner cooperativeProjectBanner) {
        return bannerService.deleteCooperativeProjectBanner(cooperativeProjectBanner);
    }

}
